<template>
    <div class="love">
        <div class="love-comtent">
            <div class="love-comtent-div">
                <div class="love-comtent-divu">
                    <i class="el-icon-user"></i>
                    <input  type="text" placeholder="账号" v-model="username">
                </div>
                <div class="love-comtent-divu">
                    <i class="el-icon-lock"></i>
                    <input type="password" placeholder="密码" v-model="password">
                </div>
                <div  class="love-comtent-divbtn">
                    <button @click="login">登录</button>
                </div>
                
            </div>
            
        </div>
    </div>
</template>

<script>
import {requestLogin} from '../api/requestPost'
export default {
    name:'Love',
    data () {
        return {
            username:null,
            password:null,
            timelogin:null,
        }
    },
    methods: {
        login(){
            if(this.timelogin){
                clearTimeout(this.timelogin)

            }
                this.timelogin=setTimeout(()=>{
                    if(this.username && this.password ){
                    requestLogin(this.username,this.password).then(res=>{ 
                        if(res.data['return']=='none'){
                            
                            this.$message({
                        message: '账号或密码错误!',
                        type: 'warning'
                        });
                        }else{
                            
                            // sessionStorage['token']=res.data.data
                            this.$store.dispatch('settoken', res.data.data)
                            this.$message({
                            message: '登录成功',
                            type: 'success'
                            });
                            this.$router.push('Postablog')
                        }
                        
                    
                    })
                    
                }else{
                    this.$message({
                        message: '不能留空哦宝贝',
                        type: 'warning'
                        });
                }

                },1000)
            
            
        }
    },
    beforeDestroy () {
        clearTimeout(this.timelogin)
    }
}
</script>

<style>
    .love-comtent-divbtn button:hover{
        opacity: .5;
        background: rgba(0,0,0,0.3);
        color: rgb(248, 248, 248);
        transition: all .6s;
        -webkit-transition: all .6s;
        -moz-transition: all .6s;
        -o-transition: all .6s;
    }
    .love-comtent-divbtn button{
        cursor: pointer;
        border: none;
        width: calc(100% - 40%);
        border-radius: 5px;
        line-height: 27px;
        background: #3a4557;
        color: #fff;
    }
    .love-comtent-divbtn{
        margin-top: 20px;
        display: flex;
        
    }
    .love-comtent-divu i{
        font-size: 20px;
        font-weight: 500;
        text-align: center;
        padding-top:5px ;

    }
    .love-comtent-divu input{
        outline: none;
        border: none;
        background: transparent;
        border-bottom: 1px solid rgb(95, 90, 90);
        font-size: 15px;
        line-height: calc(100% + 13px);
        margin-left:10px ;
        border-radius: 3px;
        width: calc(100% - 50%);
        /* height: 30px; */
    }
    .love-comtent-divu{
        display: flex;
        margin-bottom: 10px;
        
        
        
    }
    .love-comtent-div div{
        justify-content: center;
    }
    .love-comtent-div{
        flex-direction: column;
        width: 40%;
        
        display: flex;
        
        
    }
    
    .love-comtent:not(.not-top-img)::before{
        position: absolute;
        border-radius: 20px;
        width: 100%;
        height: 100%;
        background-color: rgba(0,0,0,0.3);
        content: '';
    }
    .love-comtent:not(.not-top-img):hover::before {
        height: 0;
        transition: all 1s;
        -webkit-transition: all 1s;
        
        -moz-transition: all 1s;
        -o-transition: all 1s;
    }
    .love-comtent{  
        background: url('https://gitee.com/Cezzz/image2_repo/raw/master/img/20220114172154.jpg');
        width: 1200px;
        height: 700px;
        position: relative;
        display: flex;
        align-items: center;
        -webkit-box-align: center;
        justify-content: center;
        background-size: 1300px;
        border-radius: 20px;
        box-shadow: 0 3px 8px 6px rgba(7,17,27,0.05);;
    }
    .love{
        
        width: 100%;
        max-width: 1200px;
        margin: 0 auto;
        flex: 1 auto;
        display: flex;
        padding: 40px 15px;
    }
</style>